package com.sanjin.controller;

import com.sanjin.entity.ParkOrder;
import com.sanjin.exception.MyException;
import com.sanjin.service.ParkOrderService;
import com.sanjin.service.ParkSpace2WxMiniUserService;
import com.sanjin.utils.ResponseVoUtils;
import com.sanjin.utils.SecurityUtils;
import com.sanjin.utils.ValidateUtils;
import com.sanjin.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: sanjin
 * @date: 2019/5/15 21:25
 */
@Api(tags = "摄像头调用API")
@RestController
@RequestMapping("/shexiangtou")
public class ParkSpace2WxMiniUserController {

    @Autowired
    private ParkOrderService orderService;

    @Autowired
    private ParkSpace2WxMiniUserService parkSpace2WxMiniUserService;

    @ApiOperation("车辆进入停车场请求接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carLicenseNumber",value = "车牌号码",paramType = "query")
    })
    @PostMapping("/enter")
    public ResponseVo enter(@RequestParam String carLicenseNumber) {
        if (!ValidateUtils.valideteCarLicenseNumber(carLicenseNumber)) {
            throw new MyException("车牌号码不合法");
        }
        // 添加车辆进入记录
        parkSpace2WxMiniUserService.createCarEnter(carLicenseNumber);
        return ResponseVoUtils.success();
    }

    @ApiOperation("车辆离开停车场请求接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carLicenseNumber",value = "车牌号码",paramType = "query")
    })
    @PostMapping("/leave")
    public ResponseVo leave(@RequestParam String carLicenseNumber) {
        // 添加车辆离开记录
        ParkOrder order = parkSpace2WxMiniUserService.createCarLeave(carLicenseNumber);
        return ResponseVoUtils.success(order);
    }

    @ApiOperation(value = "【通过订单id获取订单】")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId",value = "订单id",paramType = "query")
    })
    @GetMapping("")
    public ResponseVo getOrder(@RequestParam Integer orderId) {
        ParkOrder parkOrder = orderService.queryOrderByOrderId(orderId);
        return ResponseVoUtils.success(parkOrder);
    }
}
